﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Util;

namespace Util
{
    public class Trasformar<T>
    {

        public IEnumerable<T> toIEnumerable(ArrayList lista, Type obj, string property)
        {
            ArrayList list = new ArrayList();

            foreach (Object item in lista)
            {

                Reflections reflections = new Reflections();

                Object newObject = reflections.create( obj );

                reflections.setPropertyValue(newObject, property, item);

                list.Add( newObject );

            }

            IEnumerable<T> e = (IEnumerable<T>)list.Cast<T>().GetEnumerator();

            return e;
        }

        public ArrayList toArrayList(ArrayList lista, Type obj, string property)
        {
            ArrayList list = new ArrayList();

            foreach (Object item in lista)
            {

                Reflections reflections = new Reflections();

                Object newObject = reflections.create(obj);

                reflections.setPropertyValue(newObject, property, item);

                list.Add(newObject);

            }

            return list;
        }

    }
}